package com.sc.nft.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.sc.nft.admin.request.CollectionExportRequest;
import com.sc.nft.admin.request.TempRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.TempCityServerCentre;
import com.sc.nft.entity.TempDealOrder;
import com.sc.nft.entity.vo.SecondOrderExportListVO;
import com.sc.nft.entity.vo.SecondOrderExportVO;
import com.sc.nft.entity.vo.TempDealOrderVO;
import com.sc.nft.entity.vo.TempWorkRoomVO;
import com.sc.nft.enums.ApplicationRequirementUpOrDownEnum;
import com.sc.nft.service.TempDealOrderService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 朱梦晨
 * @Description: 交易列表导出模块
 * @date 2024-07-26
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/temp/dealOrder")
@Api(tags="交易列表导出模块")
public class TempDealOrderController {

    private final TempDealOrderService tempDealOrderService;



    @PostMapping(value = "/collectionExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "交易列表导出", notes = "交易列表导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result tempWorkRoomExcel(@Valid @RequestBody CollectionExportRequest request){
        if (CollUtil.isEmpty(request.getCollectionIdList()) && (ObjectUtil.isNull(request.getEndTime()) || ObjectUtil.isNull(request.getStartTime()))){
            return Result.fail("藏品标题筛选和交易时间筛选不能都为空");
        }
        return Result.success(tempDealOrderService.saveTempDealOrder(request.getStartTime(),request.getEndTime(),
                request.getMarketType(),request.getCollectionIdList()));
    }


    @PostMapping(value = "/download", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "交易列表导出下载", notes = "交易列表导出下载", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<TempDealOrderVO>> findWorkRoomList(@Valid @RequestBody TempRequest request){
        List<TempDealOrder> tempDealOrderList = tempDealOrderService.findTempDealOrderList(request.getExportRecordsId());
        List<TempDealOrderVO> secondOrderExportVOList = BeanUtil.copyToList(tempDealOrderList, TempDealOrderVO.class);
        return Result.success(secondOrderExportVOList);
    }

}
